package cn.tedu.review;

import org.omg.Messaging.SYNC_WITH_TRANSPORT;

import java.math.BigDecimal;
import java.util.Scanner;

/*本类用于复写浮点数运算不精确解决案例*/
public class TestBig {
    public static void main(String[] args) {
        System.out.println("请输入两个小数:");
        double a = new Scanner(System.in).nextDouble();
        double b = new Scanner(System.in).nextDouble();

        //创建BigDecimal对象
        BigDecimal bd1 = new BigDecimal(a+"");
        BigDecimal bd2 = new BigDecimal(b+"");

        //定义变量保存结果
        BigDecimal bd3;

        //进行运算
        bd3  = bd1.add(bd2);
        System.out.println("加法"+bd3);
        bd3  = bd1.subtract(bd2);
        System.out.println("减法"+bd3);
        bd3  = bd1.multiply(bd2);
        System.out.println("乘法"+bd3);
        bd3  = bd1.divide(bd2,5,BigDecimal.ROUND_HALF_UP);
        System.out.println("除法"+bd3);


    }
}
